package cn.itsource.user.service.impl;

import cn.itsource.basic.util.*;
import cn.itsource.user.domain.Logininfo;
import cn.itsource.user.domain.User;
import cn.itsource.user.dto.AccountDto;
import cn.itsource.user.dto.EmailDto;
import cn.itsource.user.mapper.LogininfoMapper;
import cn.itsource.user.mapper.UserMapper;
import cn.itsource.user.service.IUserService;
import cn.itsource.basic.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author itsource
 * @since 2023-03-04
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private LogininfoMapper logininfoMapper;

    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public AjaxResult registerEmail(EmailDto emailDto) {
        User user = new User();
        if (null != emailDto){
            user.setUsername(emailDto.getEmail());
            user.setEmail(emailDto.getEmail());
            //处理盐值和密码
            String sate = StrUtils.getComplexRandomString(32);
            String md5Pwd = MD5Utils.encrypByMd5(emailDto.getPassword() + sate);
            user.setPassword(md5Pwd);
            user.setSalt(sate);
            user.setState(1);
  //          Logininfo logininfo = new Logininfo();
//            BeanUtils.copyProperties(user,logininfo);
//            logininfo.setDisable(true);
//            logininfo.setType(1);
//            logininfoMapper.add(logininfo);
            userMapper.add(user);
        }

        return AjaxResult.me().success(user);
    }


}
